/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package triploa;
import java.io.IOException;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParserException;

/**
 *
 * @author Edoardo
 */
public class Locazione {
   private Locazione()
{
    lat=0;
lng=0;
address=null;
}
    private float lat;
    private float lng;
    private String address;
    private String description;
    private String gettingInUser;
    private String gettingOffUsers;
    public static final String LOCATION_TAG="a:GeoLoc";
    public static final String LAT_TAG="a:lat";
    public static final String LONG_TAG="a:lng";
    public static final String ADDRESS_TAG="a:address";
    public static final String DESCRIPTION_TAG="a:description";
public static final String GETTING_IN_TAG="a:gettingInUser";
public static final String GETTING_OFF_TAG="a:gettingOffUsers";
/**
 * call for getting a new instance of this class from xml
 * @param p Parser
 * @return a new instance of FeedBack
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
    public static Locazione create(KXmlParser p) throws IOException, XmlPullParserException
{
    Locazione l=new Locazione();
    l.update(p);
    if( l.lat==0&&l.lng==0&&l.address==null) return null;
    return l;
}
    /**
 * Update this object class from xml parser
 * @param p Parser
 * @throws java.io.IOException
 * @throws org.xmlpull.v1.XmlPullParserException
 */
public void update(KXmlParser p)throws IOException, XmlPullParserException
{
       boolean exit = false, travel = false;
        int token = -1;
        String n="",lasttag=n;
        while (!exit) {
            token = p.next();
            switch (token) {
                case KXmlParser.START_DOCUMENT:
                    break;
                case KXmlParser.END_DOCUMENT:
                    exit = true;  //exit form while
                    break;
                case KXmlParser.START_TAG:
                    System.out.println(this.getClass().getName()+p.getName());
                    if (p.getName().equals(LOCATION_TAG)) {
                        travel = true;
                    }
                    if(travel) lasttag=p.getName();
                    break;
                case KXmlParser.END_TAG:
                    if (travel) {
                        if (p.getName().equals(LOCATION_TAG)) {
                            travel = false;
                            exit = true;
                            break;
                        }
                        
                    }
                    lasttag=n;
                    break;
                case KXmlParser.TEXT:
                    if (lasttag.equals(LAT_TAG)) {
                        
                        lat = Float.parseFloat(p.getText());
                        System.out.println("lat "+lat);
                    }
                    
                    if (lasttag.equals(LONG_TAG)) {
                        lng = Float.parseFloat(p.getText());
                        System.out.println("lng "+lng);
                    }
                    if (lasttag.equals(ADDRESS_TAG)) {
                        address = p.getText();
                        System.out.println("address "+address);
                    }
                    if (lasttag.equals(DESCRIPTION_TAG)) {
                        description = p.getText();
                    }
                    if (lasttag.equals(GETTING_IN_TAG)) {
                        this.gettingInUser= p.getText();
                        
                    }
                    
                    if (lasttag.equals(GETTING_OFF_TAG)) {
                        this.gettingOffUsers=p.getText();
                    }
                    
                    
                    break;
            }
        }
}

    public float getLat() {
        return lat;
    }

    public void setLat(float lat) {
        this.lat = lat;
    }

    public float getLng() {
        return lng;
    }

    public void setLng(float lng) {
        this.lng = lng;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getGettingInUser() {
        return gettingInUser;
    }

    public void setGettingInUser(String gettingInUser) {
        this.gettingInUser = gettingInUser;
    }

    public String getGettingOffUsers() {
        return gettingOffUsers;
    }

    public void setGettingOffUsers(String gettingOffUsers) {
        this.gettingOffUsers = gettingOffUsers;
    }

}